//
//  LMPopMenu.m
//  李明微博
//
//  Created by 张青花 on 15/12/4.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "LMPopMenu.h"

@implementation LMPopMenu


+ (instancetype)showInRect:(CGRect)rect
{
    LMPopMenu *menu = [[LMPopMenu alloc] initWithFrame:rect];
    
    menu.userInteractionEnabled=YES;
    
    menu.image = [UIImage imageWithStretchableName:@"popover_background"];
    
    [LMKeyWindow addSubview:menu];
    
    return menu;
}


+ (void)hide
{
    for (UIView *popMenu in LMKeyWindow.subviews) {
        
        if ([popMenu isKindOfClass:self]) {
            [popMenu removeFromSuperview];
        }
    }
}

- (void)setContentView:(UIView *)contentView
{
    [_contentView removeFromSuperview];
    _contentView = contentView;
    
    [self addSubview:contentView];
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat y = 9;
    CGFloat margin = 5;
    CGFloat x = margin;
    CGFloat w = self.width - 2 * margin;
    CGFloat h = self.height - y - margin;
    _contentView.frame = CGRectMake(x ,y, w, h);
}


@end
